<template>
  <!-- 教学日志 -->
  <div id="teachlog">
    <div class="title">{{ applyTitle }}从业资格培训教学日志</div>
    <div>
      <div class="flex-justify">
        <span>
          <label v-if="isPassengerTranport(applyTitle)"
            >括号中标注“客”者 -- 仅作为道路旅客运输驾驶员的教学项目或学时</label
          >
        </span>
        <span v-if="teachInfo.enrollBatch">[{{ teachInfo.enrollBatch }}]</span>
      </div>
      <div class="flex-justify">
        <span>
          <label v-if="isPassengerTranport(applyTitle)"
            >括号中标注“货”者 -- 仅作为道路货物运输驾驶员的教学项目或学时</label
          >
        </span>
        <span>学员编号：{{ teachInfo.studentCode }}</span>
      </div>
    </div>
    <div>
      <table class="teachtable"  border="0" cellspacing="0" cellpadding="0">
        <colgroup>
          <col width="10%" v-for="it in 10" :key="it" />
        </colgroup>
        <tbody>
          <tr>
            <td colspan="4">
              <div class="flex">
                <div class="flex-title">
                  <span class="bold">培训机构名称：</span>{{ teachInfo.schoolName }}
                </div>
              </div>
            </td>
            <td colspan="3">
              <div class="flex">
                <div class="flex-title">
                  <span class="bold">学员姓名：</span>{{ teachInfo.name }}
                </div>
              </div>
            </td>
            <td colspan="3">
              <div class="flex">
                <div class="flex-title">
                  <span class="bold">申请类别：</span>
                </div>
                <div style="word-break: break-all;">{{ teachInfo.applyType }}</div>
              </div>
            </td>
          </tr>
          <tr>
            <td colspan="10">
              <div class="flex">
                <div class="lineheight15">
                  <span class="bold">培训目标 : </span>{{ teachInfo.trainTarget }}
                </div>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
      <template v-for="item in teachInfo.studentInfoDetails">
        <div
          v-if="
            !(
              item.educationDictionary.educationSubject == '区域实操' &&
              teachInfo.applyType.includes('网络预约')
            )
          "
        >
          <table class="teachtable"  border="0" cellspacing="0" cellpadding="0">
            <colgroup>
              <col width="10%" v-for="it in 10" :key="it" />
            </colgroup>
            <tbody>
              <tr>
                <td colspan="2" rowspan="2">
                  <h5>
                    {{ item.educationDictionary.educationSubject }}学时：
                    <span
                      v-if="
                        isPassengerTranport(applyTitle) &&
                        item.educationDictionary.educationSubject == '理论'
                      "
                      >{{ item.educationDictionary.theoryPeriod }}(客) <br />
                      48(货)</span
                    >
                    <span
                      v-else-if="
                        isPassengerTranport(applyTitle) &&
                        item.educationDictionary.educationSubject == '应用能力'
                      "
                      >{{ item.educationDictionary.theoryPeriod }}(客)<br />
                      8(货)</span
                    >
                    <span v-else>{{ item.educationDictionary.theoryPeriod }}</span>
                  </h5>
                </td>
                <td colspan="4">
                  <h5>教学项目</h5>
                </td>
                <td colspan="4">
                  <h5>教学目标</h5>
                </td>
              </tr>
              <tr>
                <td colspan="4">
                  <div
                    class="flex lineheight15"
                    v-for="(some, i) in item.educationDictionary.educationProject"
                    :key="`some1-${i}`"
                  >
                    {{ some }}
                  </div>
                </td>
                <td colspan="4">
                  <div
                    class="flex lineheight15"
                    v-for="(some, i) in item.educationDictionary.educationTarget"
                    :key="`some-${i}`"
                  >
                    {{ some }}
                  </div>
                </td>
              </tr>
              <tr
                v-if="
                  item.educationDictionary.educationSubject === '理论' &&
                  isDangerTranport(applyTitle)
                "
              >
                <td colspan="10">
                  <h5>爆炸品运输从业人员应学习带*内容；剧毒化学品运输从业人员应学习带#内容</h5>
                </td>
              </tr>
            </tbody>
          </table>

          <table class="teachtable"  border="0" cellspacing="0" cellpadding="0">
            <colgroup>
              <col width="10%" />
              <col width="10%" />
              <col
                v-for="it in item.studyInfoDays.length"
                :width="getWidth(item.studyInfoDays.length)"
                :key="it"
              />
            </colgroup>
            <tbody>
              <tr v-for="(some, index) in item.studyList" :key="index">
                <td colspan="2">
                  <h5>{{ some.label }}</h5>
                </td>
                <td v-for="(it, idx) in some.value" :key="`sub_${idx}`">
                  <div class="studentsign">
                    <img class="studentimg" v-if="some.prop === 'name' && teachInfo.signature" :src="getImage(teachInfo.signature)"/>
                    <span v-else>{{ it[some.prop] }}</span>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </template>

      <table class="teachtable"  border="0" cellspacing="0" cellpadding="0">
        <colgroup>
          <col width="10%" v-for="it in 10" :key="it" />
        </colgroup>
        <tbody>
          <tr>
            <td colspan="7">
              <div class="flex items-center" style="height: 60px">
                <h5>考核意见：</h5>
                <span>{{ teachInfo.testRemarks }}</span>
              </div>
            </td>
            <td colspan="3">
              <div class="flex items-center">
                <h5>考核人签字：</h5>
                <span>{{ teachInfo.testerName }}</span>
              </div>
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <h5 style="width: 160px">培训机构审核意见</h5>
            </td>
            <td colspan="8">
              <div class="flex justify-end">
                <div class="flex items-end" style="height: 100px">（盖章）</div>
                <div v-if="teachInfo.signaturePhoto">
                  <div class="sign-img">
                    <div class="signature-regular">培训合格</div>
                    <div class="signature-time">{{ teachInfo.signatureTime }}</div>
                    <img :src="getImage(teachInfo.signaturePhoto)" alt="" />
                  </div>
                </div>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive, toRefs, watch } from "vue-demi"
const applyTypeArray = [
  { name: '经营性道路旅客运输驾驶员', label: '道路客货运输驾驶员' },
  { name: '道路货物运输驾驶员', label: '道路客货运输驾驶员' },
  { name: '道路危险货物运输驾驶员', label: '道路危险货物运输驾驶员' },
  { name: '道路危险货物运输装卸管理人员', label: '道路危险货物运输装卸管理人员' },
  { name: '道路危险货物运输押运人员', label: '道路危险货物运输押运人员' },
  { name: '放射性物品道路运输驾驶员', label: '放射性物品道路运输驾驶员' },
  { name: '放射性物品道路运输装卸管理人员', label: '放射性物品道路运输装卸管理人员' },
  { name: '放射性物品道路运输押运人员', label: '放射性物品道路运输押运人员' },
  { name: '剧毒化学品道路运输驾驶员', label: '剧毒化学品道路运输驾驶员' },
  { name: '剧毒化学品道路运输装卸管理人员', label: '剧毒化学品道路运输装卸管理人员' },
  { name: '剧毒化学品道路运输押运人员', label: '剧毒化学品道路运输押运人员' },
  { name: '爆炸品道路运输驾驶员', label: '爆炸品道路运输驾驶员' },
  { name: '爆炸品道路运输装卸管理人员', label: '爆炸品道路运输装卸管理人员' },
  { name: '爆炸品道路运输押运人员', label: '爆炸品道路运输押运人员' },
  { name: '巡游出租汽车驾驶员', label: '出租汽车驾驶员' },
  { name: '网络预约出租汽车驾驶员', label: '出租汽车驾驶员' }
]
import { getImage } from '../../utils/common'

export default defineComponent({
  name: "teachLog",
  props: {
    childData: {
      type: Object,
      default: () => {}
    }
  },
  setup(prop) {
    const data = reactive({
      studyList: [
        { label: '次数/日期', value: [], prop: 'timeDate' },
        { label: '教学项目', value: [], prop: 'trainSubject' },
        { label: '所用学时', value: [], prop: 'trainHour' },
        { label: '学员签字', value: [], prop: 'name' },
        { label: '教练员评价及签字', value: [], prop: 'teacherName' }
      ],
      teachInfo: {
        schoolName: '',
        applyType: '',
        studyInfoDays: [],
        trainTarget: '',
        signatureTime: '',
        signaturePhoto: '',
        studentCode: ''
      },
      applyTitle: ''
    })
    const isPassengerTranport = (name) => {
      return name == '道路客货运输驾驶员'
    }
    const isDangerTranport = (name) => {
      return ['危险', '剧毒', '爆炸'].some(it => name.includes(it))
    }
    watch(() => prop.childData, (newVal) => {
        if (newVal && Object.keys(newVal).length) {
          const defaultList = new Array(8).fill({})
          let teachInfo = {
            ...newVal
          }
          teachInfo.studentInfoDetails = teachInfo.studentInfoDetails?.map(item => {
            const len = item.studyInfoDays?.length
            let studyInfoDays = defaultList
            if (len > 0) {
              studyInfoDays = item.studyInfoDays?.map((o, index) => {
                o.trainHour = o.trainHour > 0 ? o.trainHour : 0
                o.teacherName = o.teacherName ?? '-'
                o.timeDate = `${index + 1}/${o.date}`
                return o
              })
              if (len < 8) {
                let fileArr = new Array(8 - len).fill({})
                studyInfoDays = [...studyInfoDays, ...fileArr]
              }
            }

            return {
              ...item,
              studyInfoDays,
              educationDictionary: {
                ...item.educationDictionary,
                educationTarget: item.educationDictionary?.educationTarget?.split('。'),
                educationProject: item.educationDictionary?.educationProject?.split('。')
              },
              studyList: data.studyList?.map(it => {
                return {
                  ...it,
                  value: studyInfoDays
                }
              })
            }
          })
          teachInfo.trainTarget = newVal.studentInfoDetails?.[0]?.educationDictionary?.trainTarget

          data.applyTitle = applyTypeArray.find(item => item.name == teachInfo.applyType)?.label

          data.teachInfo = teachInfo
        }
    }, {
      immediate: true,
      deep: true
    })

    return {
      ...toRefs(data),
      getImage,
      getWidth(length) {
        return `${80 / length}%`
      },
      isDangerTranport,
      isPassengerTranport,
    }
  }
})
</script>

<style lang="scss" scoped>
#teachlog {
  font-size: 14px;
  margin: 0 auto;
  width: 800px;
  .lineheight15 {
    line-height: 16px;
    font-size: 14px;
  }
  .flex-justify {
    display: flex;
    justify-content: space-between;
  }
  .title {
    text-align: center;
    font-size: 25px !important;
    font-weight: bold !important;
    padding: 10px 0;
  }
  .teachtable {
    width: 800px;
    margin: 2px auto 0;
    border-top: 1px solid gray;
    border-left: 1px solid gray;
    td,
    th {
      text-align: center;
      max-width: 90px;
      padding: 1px 5px;
      border-bottom: 1px solid gray;
      border-right: 1px solid gray;
      font-size: 14px;
    }
    h5,
    h6 {
      margin: 2px 0;
      font-size: 14px;
    }
    .flex {
      display: flex;
      text-align: left;
      align-items: center;
    }
    .items-center {
      align-items: center;
    }
    .flex-title {
      @extend .flex;
      align-items: start;
      margin: 0;
      white-space: nowrap;
      min-width: 60px;
    }
    .bold {
      font-weight: bold;
    }
    .justify-end {
      justify-content: end;
    }
    .items-end {
      align-items: end;
    }
    .studentsign {
      display: flex;
      justify-content: center;
      align-items: center;
      .studentimg {
        width: 60px;
        height: 20px;
      }
    }
    
    .sign-img {
      width: 100px;
      height: 100px;
      position: relative;
      img {
        width: 100%;
        height: 100%;
      }
      .signature-time, .signature-regular {
        position: absolute;
        margin: auto;
        left: 0;
        right: 0;
        bottom: 0;
        text-align: center;
        font-size: 12px;
        height: 50px;
      }
      .signature-regular {
        top: 0;
      }
      .signature-time {
        top: 25px;
      }
    }
  }
}
</style>
